/**
 * @param {number[]} heights
 * @return {number}
 */
var heightChecker = function(heights) {
  var tmp = [...heights]
  tmp.sort((a, b) => a - b)
  var count = 0
  for (let i = 0; i < heights.length; i++) {
    if (heights[i] != tmp[i]) count++
  }
  return count
}

console.log(heightChecker([1, 1, 4, 2, 1, 3]))
